feat: Emit effects for assignments to program rule variables backed by a field [DHIS2-21730]#186
Open
enricocolasante wants to merge 3 commits into
Open
feat: Emit effects for assignments to program rule variables backed by a field [DHIS2-21730]#186enricocolasante wants to merge 3 commits into
enricocolasante wants to merge 3 commits into
Conversation
…y a field [DHIS2-21730]
ASSIGN actions targeting a program rule variable now emit a RuleEffect
when the variable is backed by a data element or tracked entity
attribute, with the backing field and attributeType injected into the
effect action so consumers can apply it like a direct field assignment.
Emission is matched to the evaluation context (data elements in the
event pass, attributes in the enrollment pass) so evaluateAll emits
each assignment exactly once. Calculated values keep their silent
value-map-only behavior, and rule chaining is unchanged.
The two ASSIGN modes are now dispatched through the new sealed
AssignTarget type (RuleAction.assignTarget()), which accepts both
#{variableName} and A{variableName} content notations and reports
malformed actions with actionable error messages instead of
"unexpected exception: null".
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
fb69d4a to
0627269
Compare
…effects [DHIS2-21730]
|
vgarciabnz
reviewed
Jul 14, 2026
| * `content` value, or when `content` is not a program rule variable reference like | ||
| * `#{variableName}`. | ||
| */ | ||
| fun assignTarget(): AssignTarget? { |
Member
There was a problem hiding this comment.
This method is public in RuleAction and it is a sealed class. If this object is expected to be managed by the client, I would check how the sealed class is managed from Java code in the backend. I think the interoperability for sealed classes is good enough in Java. I wonder how it will look like from JS code, maybe you can publish a beta and ask Tony to check it.
If this method is not supposed to be public, let's make it internal.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



DHIS2-21730: Emit effects for assignments to program rule variables backed by a field
Summary
ASSIGN actions targeting a program rule variable (
content = #{variableName}orA{variableName}) previously only mutated the in-memory value map, so the assigned value was never propagated back to the data element or tracked entity attribute the variable is backed by. This PR makes the engine emit aRuleEffecttargeting the backing field for such assignments, and hardens validation and error reporting around ASSIGN targets.Changes
ASSIGN target resolution (
RuleAction.assignTarget()/AssignTarget)AssignTargetwith three cases:Field— assign to the data element/attribute named by the action'sfield; emits an effect for the caller to apply.Variable— assign to a program rule variable referenced incontent; updates the evaluation state so subsequent rules see the new value. Both#{variableName}andA{variableName}notations are accepted.Invalid— the action defines neitherfieldnorcontent, orcontentis not a variable reference; carries a human-readable reason.RuleActiongainsASSIGN/ERRORtype constants and an internalwithAssignBacking(field, attributeType)helper.Effect emission for variable assignments (
RuleConditionEvaluator)RuleEffectcarrying a copy of the action with the backingfieldandattributeTypeinjected, making the effect self-contained for consumers.hasEnrollmentPass), otherwise the event pass emits them (single-event evaluation, executions without an enrollment, rules scoped to a program stage), so assignments are never silently dropped.Validation & error reporting
RuleConfigurationException: malformed ASSIGN targets (AssignTarget.Invalid) are reported as error effects, like expression errors, instead of surfacing as unexpected exceptions.addRuleErrorResultdeduplicated.unwrapVariableNameutility (superseded byassignTarget());currentDate()is now internal.Logger
Loggergains awarninglevel, wired up on JVM (Level.WARNING), JS (console.warn) and native.